//
//  PaySuccessViewController.m
//  PeopleStreet
//
//  Created by 辰领科技 on 16/4/1.
//  Copyright © 2016年 yuf. All rights reserved.
//

#import "PaySuccessViewController.h"
#import "ShoppingHomeGuessProductCollection.h"
#import "ShoppingProductDetailViewController.h"
#import "WaittingCommentDetailViewController.h"
static NSString *CellWithGuessIdentifier = @"ShoppingHomeGuessProductCollection";
@interface PaySuccessViewController ()<UICollectionViewDataSource,UICollectionViewDelegate>
@property (strong, nonatomic) IBOutlet UIView *navView;
@property (strong, nonatomic) IBOutlet UIScrollView *scroView;
@property (strong, nonatomic) IBOutlet UICollectionView *collectionView;
@property (strong, nonatomic) IBOutlet UIButton *seeIndentButton;
@property (strong, nonatomic) IBOutlet UIButton *goHomeButton;
@property (weak, nonatomic) IBOutlet UILabel *payType;
@property (weak, nonatomic) IBOutlet UILabel *indentMoney;
@property (weak, nonatomic) IBOutlet UILabel *forsaleMoney;
@property (weak, nonatomic) IBOutlet UILabel *codePayMoney;
@property (weak, nonatomic) IBOutlet UIButton *getCode;
@property(nonatomic,strong)NSMutableArray * goodsGuessLikeArray;

@end

@implementation PaySuccessViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _goodsGuessLikeArray = [NSMutableArray array];
    // Do any additional setup after loading the view.
    [self initViewLayout];
    [self getGuessGoods];
}

- (void)initViewLayout{
    [self adaptiveViewLayout:self.view];
    [self adaptiveViewLayout:self.navView];
    [self adaptiveViewLayout:self.scroView];
    
    _scroView.contentSize = flexibleSize(CGSizeMake(0, 505), YES);
    
    _seeIndentButton.layer.masksToBounds = YES;
    _seeIndentButton.layer.borderWidth = 1;
    _seeIndentButton.layer.borderColor = [UIColor colorWithWhite:0.937 alpha:1.000].CGColor;
    
    _goHomeButton.layer.masksToBounds = YES;
    _goHomeButton.layer.borderWidth = 1;
    _goHomeButton.layer.borderColor = [UIColor colorWithWhite:0.937 alpha:1.000].CGColor;
    
    NSMutableAttributedString * payType =[[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"支付方式:%@",_payTypeStr]];
    [payType addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:NSMakeRange(payType.length-_payTypeStr.length, _payTypeStr.length)];
    _payType.attributedText = payType;
    
    NSString * money = [NSString stringWithFormat:@"%d",[_payMoney intValue]];
    NSMutableAttributedString * payMoney = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"订单金额:￥%@",money]];
    [payMoney addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:NSMakeRange(payMoney.length-money.length-1, money.length+1)];
    _indentMoney.attributedText = payMoney;
    
    UICollectionViewFlowLayout *flowLayout =[[UICollectionViewFlowLayout alloc]init];
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    self.collectionView.collectionViewLayout = flowLayout;
    self.collectionView.backgroundColor =kGetColor(255, 255, 255);
    self.collectionView.userInteractionEnabled=YES;
    [self.collectionView registerNib:[UINib nibWithNibName:CellWithGuessIdentifier bundle:nil] forCellWithReuseIdentifier:CellWithGuessIdentifier];

}

- (IBAction)back:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
        [[NSNotificationCenter defaultCenter]postNotificationName:@"hadPay" object:@"1"];
   
    
}

#pragma mark == 查询猜你喜欢商品
- (void)getGuessGoods{
    if ([Common getLoginStatus]) {
        NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
        self.shareApi.delegate=self;
        [self.shareApi  requestOperationWithDic:dic withPath:SX_QueryMallUserLoveGoodsData withHttpType:@"POST" withTag:SX_QueryMallLoveGoodsDataTag];
    }else{
        NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
        [dic setObject:@"queryMallLoveGoodsData" forKey:@"method"];
        self.shareApi.delegate=self;
        [self.shareApi  requestOperationWithDic:dic withPath:SX_QueryMallLoveGoodsData withHttpType:@"POST" withTag:SX_QueryMallLoveGoodsDataTag];
    }
    
}

#pragma mark  ==== 我的积分
- (IBAction)myCode:(id)sender {
    UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"MyCodeStoryboard" bundle:nil];
    UIViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"PersonCode"];
    [self.navigationController   pushViewController:page animated:YES];
}
#pragma mark  ==== 查看订单
- (IBAction)indentDetail:(id)sender {
    UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"PersonCenterStoryboard" bundle:nil];
    WaittingCommentDetailViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"WaittingCommentDetail"];
    page.indentId = _indentId;;
    page.titleStr = @"订单详情(待发货)";
    [self.navigationController   pushViewController:page animated:YES];
}
#pragma mark  ==== 返回首页
- (IBAction)goHome:(id)sender {
    [self.navigationController  popViewControllerAnimated:YES];
}

#pragma mark -- UICollectionViewDataSource
//定义展示的UICollectionViewCell的个数
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return _goodsGuessLikeArray.count;
    
}
//定义展示的Section的个数
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

//定义每个UICollectionView 的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(91*VerticalRatio(), 144*VerticalRatio());
    
}
//定义每个UICollectionView 的 margin
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(0,10, 0, 10);
    
}
//每个UICollectionView展示的内容
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    ShoppingHomeGuessProductCollection * cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellWithGuessIdentifier forIndexPath:indexPath];
    NSDictionary *dic = _goodsGuessLikeArray[indexPath.row];
    cell.cellProductName.text = dic[@"mgooName"];
    cell.cellProuctPrice.text = [NSString stringWithFormat:@"￥%.2f",[dic[@"mgooPublishPrice"] floatValue]];
    NSString * image = dic[@"appAdertImagUri"];
    if (image.length>0) {
        [cell.cellProductImage sd_setImageWithURL:[NSURL URLWithString:image]];
    }else{
        cell.cellProductImage.image =[UIImage imageNamed:@"cloth1"];
    }
    return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"HomeStoryboard" bundle:nil];
    ShoppingProductDetailViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"ShoppingProductDetail"];
    page.goodsId = _goodsGuessLikeArray[indexPath.row][@"mgooId"];
    [self.navigationController   pushViewController:page animated:YES];
}


#pragma   mark---- GetADBanner Request Delegate

-(void)fetchDatabaseFinished:(NSMutableDictionary *)database withTag:(NSInteger)tag{
    if (tag == SX_QueryMallLoveGoodsDataTag){
        if (  [[database valueForKey:@"type"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            
        }else{
            _goodsGuessLikeArray = database[@"result"][@"pageRecord"];
            _collectionView.dataSource = self;
            _collectionView.delegate = self;
            [self.collectionView reloadData];
        }
    }
}

-(void)fetchDatabaseFailed:(NSError *)error message:(NSString *)message{
    
    //
    [self dismissWaitDialog];
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
